#include "Tokenizer.h"

const string Tokenizer::DELIMITERS("|");

Tokenizer::Tokenizer(const string& s) : m_string(s), m_offset(0), m_delimiters(DELIMITERS)
{
}

Tokenizer::Tokenizer(const string& s, const string& delimiters) : m_string(s), m_offset(0), m_delimiters(delimiters)
{
}

bool Tokenizer::nextToken() 
{
    return nextToken(m_delimiters);
}

bool Tokenizer::nextToken(const string& delimiters) 
{
    size_t i = m_string.find_first_not_of(delimiters, m_offset);
    if (string::npos == i)
    {
        m_offset = m_string.length();
        return false;
    }

    size_t j = m_string.find_first_of(delimiters, i);
    if (string::npos == j) 
    {
        m_token = m_string.substr(i);
        m_offset = m_string.length();
        return true;
    }

    m_token = m_string.substr(i, j - i);
    m_offset = j;
    return true;
}

const string Tokenizer::getToken() const
{
	return m_token;
}
